﻿@model PhoneBilling.Models.DepartmentSortModel
@{
    ViewBag.Title = "部门排序";
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
<script type="text/javascript">
    function right() {
        $("select.list option:selected").each(function () {
            $("select.resultList").append("<option value='" + $(this).val() + "'>" + $(this).html() + "</option>");
        });
        $("select.list option:selected").remove();
    }

    function allRight() {
        $("select.list option").each(function () {
            $("select.resultList").append("<option value='" + $(this).val() + "'>" + $(this).html() + "</option>");
        });
        $("select.list option").remove();
    }

    function left() {
        $("select.resultList option:selected").each(function () {
            $("select.list").append("<option value='" + $(this).val() + "'>" + $(this).html() + "</option>");
        });
        $("select.resultList option:selected").remove();
    }

    function allLeft() {
        $("select.resultList option").each(function () {
            $("select.list").append("<option value='" + $(this).val() + "'>" + $(this).html() + "</option>");
        });
        $("select.resultList option").remove();
    }

    function sumbit() {
        if ($("select.list option").length > 0) {
            alert("请把所有部门都移动到右边。");
            return;
        }
        var str = "";
        $("select.resultList option").each(function () {
            if (str == "")
                str += $(this).val();
            else
                str += "!" + $(this).val();
        });
        $("#Result").attr("value", str);

        $("form").submit();
    }
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnConfirm").ligerButton(
        {
            click: function () {
                submit();
            }
        });
        $("#btnRight").ligerButton(
        {
            click: function () {
                right();
            },
            width: 60
        });
        $("#btnAllRight").ligerButton(
        {
            click: function () {
                allRight();
            },
            width: 60
        });
        $("#btnLeft").ligerButton(
        {
            click: function () {
                left();
            },
            width: 60
        });
        $("#btnAllLeft").ligerButton(
        {
            click: function () {
                allLeft();
            },
            width: 60
        });
    });
    
</script>
@using (Html.BeginForm())
{ 
    @Html.HiddenFor(m => m.Result, new { @class = "Result" });
    <div class="department_sort">
        <div class="system_contain_group">
            <h3 class="title">
                原来的部门顺序</h3>
            @Html.ListBoxFor(m => m.List, null, new { @class = "list" })
        </div>
        <div class="system_contain_group controls">
            <div class="system_input_contain">
                <input type="button" id="btnRight" value=">" />
            </div>
            <div class="system_input_contain">
                <input type="button" id="btnAllRight" value=">>>" />
            </div>
            <div class="system_input_contain">
                <input type="button" id="btnLeft" value="<" />
            </div>
            <div class="system_input_contain">
                <input type="button" id="btnAllLeft" value="<<<" />
            </div>
        </div>
        <div class="system_contain_group">
            <h3 class="title">
                新的部门顺序</h3>
            @Html.ListBoxFor(m => m.ResultList, null, new { @class = "resultList" })
        </div>
        <div class="system_clear">
        </div>
        <div class="system_input_contain">
            <input type="button" id="btnConfirm" value="确定" />
        </div>
    </div>
}